"""
续费管理相关接口
包含用户余额查询、续费提交、订单状态、待付款订单、订单操作、订单详情、续费历史、结果推送等接口方法。
"""
from .api_utils import md5, get_tkey, post_api

def user_balance_query(userName, passWord):
    """用户余额查询接口"""
    url = "https://api.tibiot.com/api/v1/user/sum"
    tKey = get_tkey()
    pw = md5(md5(passWord) + tKey)
    data = {"userName": userName, "passWord": pw, "tKey": tKey}
    return post_api(url, data)

def user_renew_submit(userName, passWord, iccid, productId):
    """用户续费提交接口"""
    url = "https://api.tibiot.com/api/v1/renew/submit"
    tKey = get_tkey()
    pw = md5(md5(passWord) + tKey)
    data = {"userName": userName, "passWord": pw, "tKey": tKey, "iccid": iccid, "productId": productId}
    return post_api(url, data)

def renew_status_query(userName, passWord, orderId):
    """续费订单状态查询接口"""
    url = "https://api.tibiot.com/api/v1/renew/result"
    tKey = get_tkey()
    pw = md5(md5(passWord) + tKey)
    data = {"userName": userName, "passWord": pw, "tKey": tKey, "orderId": orderId}
    return post_api(url, data)

def dpaycard_query(userName, passWord):
    """待付款卡续费订单查询接口"""
    url = "https://api.tibiot.com/api/v1/renew/queryUnpaidCardOrders"
    tKey = get_tkey()
    pw = md5(md5(passWord) + tKey)
    data = {"userName": userName, "passWord": pw, "tKey": tKey}
    return post_api(url, data)

def dpaycard_handle(userName, passWord, orderId, operateType):
    """待付款卡续费订单操作接口"""
    url = "https://api.tibiot.com/api/v1/renew/unpaidCardOrderOperation"
    tKey = get_tkey()
    pw = md5(md5(passWord) + tKey)
    data = {"userName": userName, "passWord": pw, "tKey": tKey, "orderId": orderId, "operateType": operateType}
    return post_api(url, data)

def dpaycard_info_query(userName, passWord, orderId):
    """卡续费订单详情查询接口"""
    url = "https://api.tibiot.com/api/v1/renew/queryUnpaidCardOrderInfo"
    tKey = get_tkey()
    pw = md5(md5(passWord) + tKey)
    data = {"userName": userName, "passWord": pw, "tKey": tKey, "orderId": orderId}
    return post_api(url, data)

def card_renewal_history_query(userName, passWord, iccid):
    """卡续费历史记录查询接口"""
    url = "https://api.tibiot.com/api/v1/card/queryCardRenewalRecord"
    tKey = get_tkey()
    pw = md5(md5(passWord) + tKey)
    data = {"userName": userName, "passWord": pw, "tKey": tKey, "iccid": iccid}
    return post_api(url, data)

def card_renewal_history_batch_query(userName, passWord, iccid_list):
    """卡续费历史记录批量查询接口"""
    url = "https://api.tibiot.com/api/v1/renew/batchQueryCardRenewalRecord"
    tKey = get_tkey()
    pw = md5(md5(passWord) + tKey)
    data = {"userName": userName, "passWord": pw, "tKey": tKey, "iccid": iccid_list}
    return post_api(url, data)
